package org.mlz.game.model

import org.itheima.kotlin.game.core.Painter
import org.mlz.game.Config
import org.mlz.game.business.Attackable
import org.mlz.game.business.Blockable
import org.mlz.game.business.Destroyable
import org.mlz.game.business.Sufferable
import sun.security.krb5.internal.crypto.Des

/**
 *<p>
 *
 *</p>
 * CreateBy  Malingzhao
 * @date  2020/9/21
 */
/**
 * 大本营
 * 具备阻挡的功能
 * 具备接收攻击的功能
 * 具备销毁的能力
 */
class Camp(override var x: Int, override var y: Int) : Blockable, Sufferable, Destroyable {


    override var width: Int = Config.block * 2
    override var height: Int = Config.block + 32

    /**
     * 生命值
     */
    override var blood: Int = 12


    override fun draw() {
        //血量低于6个的时候画的是砖墙
        //血量低于3个的时候没有墙
        if (blood <= 3) {
            width = Config.block
            height = Config.block
            x = (Config.gameWidth - Config.block) / 2


            y = Config.gameHeight - Config.block
            Painter.drawImage("img/camp.gif", x, y)
        } else if (blood <= 6) {
            println("x=6" + x + ":" + y)

            //绘制外围的砖块
            Painter.drawImage("img/wall_small.gif", x, y)
            Painter.drawImage("img/wall_small.gif", x + 32, y)
            Painter.drawImage("img/wall_small.gif", x + 64, y)
            Painter.drawImage("img/wall_small.gif", x + 96, y)
            Painter.drawImage("img/wall_small.gif", x, y + 32)
            Painter.drawImage("img/wall_small.gif", x, y + 64)
            Painter.drawImage("img/wall_small.gif", x + 96, y + 32)
            Painter.drawImage("img/wall_small.gif", x + 96, y + 64)
            Painter.drawImage("img/camp.gif", x + 32, y + 32)
        } else {


            //绘制外围的砖块
            Painter.drawImage("img/steel_small.gif", x, y)
            Painter.drawImage("img/steel_small.gif", x + 32, y)
            Painter.drawImage("img/steel_small.gif", x + 64, y)
            Painter.drawImage("img/steel_small.gif", x + 96, y)
            Painter.drawImage("img/steel_small.gif", x, y + 32)
            Painter.drawImage("img/steel_small.gif", x, y + 64)
            Painter.drawImage("img/steel_small.gif", x + 96, y + 32)
            Painter.drawImage("img/steel_small.gif", x + 96, y + 64)
            Painter.drawImage("img/camp.gif", x + 32, y + 32)
        }


    }

    override fun notifySuffer(attackable: Attackable): Array<View>? {
        //被打的时候
        blood -= attackable.attackPower
        if (blood == 3 || blood == 6) {


            val x = x - 32
            val y = y - 32
            return arrayOf(
                Blast(x, y),
                Blast(x + 32, y),
                Blast(x + Config.block, y),
                Blast(x + Config.block + 32, y),
                Blast(x + Config.block * 2, y),
                Blast(x, y + 32),
                Blast(x, y + Config.block),
                Blast(x, y + Config.block + 32),
                Blast(x + Config.block * 2, y + 32),
                Blast(x + Config.block * 2, y + Config.block),
                Blast(x + Config.block * 2, y + Config.block + 32)
            )
        }
        return null
    }

    /**
     * 判断是否销毁了
     */
    override fun isDestroyed(): Boolean = blood <= 0

    /**
     * 死给你看的功能 ? 可以为空
     */
    override fun showDestroy(): Array<View>? {

        return arrayOf(
            Blast(x - 32, y - 32),
            Blast(x, y - 32),
            Blast(x + 32, y - 32),
            Blast(x - 32, y),
            Blast(x, y),
            Blast(x + 32, y),
            Blast(x - 32, y + 32),
            Blast(x, y - 32),
            Blast(x + 32, y + 32)
        )

    }

}
